package com.itlong.cloud.property.service.impl;

import com.itlong.cloud.POJO.PO.DeviceBusinessChangeLogPO;
import com.itlong.cloud.PlatformConstants;
import com.itlong.cloud.property.dao.IDeviceBusinessChangeLogDao;
import com.itlong.cloud.property.service.IDeviceBussinessChangeLogService;
import com.itlong.cloud.utils.data.handler.SqlUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

/**
 * <desc>
 *      BussinessChangeLog服务层接口实现类
 * </desc>
 *
 * @createDate 2017/10/31
 */
@Service
public class DeviceBussinessChangeLogServiceImpl implements IDeviceBussinessChangeLogService {

    @Autowired
    IDeviceBusinessChangeLogDao iDeviceBusinessChangeLogDao;

    /**
     * <desc>
     *      批量插入BussinessChangeLogPO对象
     * <desc/>
     * @param  changeLogPOS 插入的对象集
     * @author Biao.R
     * @createDate 2017/10/31
     */
    @Override
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public void batchSave(List<DeviceBusinessChangeLogPO> changeLogPOS) throws Exception {
        if (changeLogPOS != null && !changeLogPOS.isEmpty()) {
            List<Map<String, Object>> saveList = new ArrayList<>();
            for (DeviceBusinessChangeLogPO changeLogPO : changeLogPOS) {
                //从数据库中查找，并去重合并
                Map<String,Object> params = new HashMap<>();
                List<DeviceBusinessChangeLogPO> sourcePOS = iDeviceBusinessChangeLogDao.getByParams(params);
                if(sourcePOS !=null && !sourcePOS.isEmpty()){

                }


                changeLogPO.setCreateTime(new Date());
                changeLogPO.setStatus(0);
                saveList.add(SqlUtil.durableData(changeLogPO, PlatformConstants.TABLE_SAVE));
            }
            iDeviceBusinessChangeLogDao.batchSave(saveList);
        }
    }
}